require(["jquery",'public','weui'],function($,public,weui) {
    //public.headertitle("账户登录");
    //public.footer(4);
    public.allocator();

    //页面加载完毕
    public.loaded();

    //提交注册
	$('.sign_in_main').on('click','.login',function(event){
		event.preventDefault();
		var $this = $(this);
		if($this.hasClass('on')){
			return false;
		}
		var data = {
			user_username: $('#user_name').val(),
			user_password: $('.project_password').val().trim(),
		};
		if(data.user_username.length == 0){
			$.alert('请输入用户名');
			return false;
		}
		
		if(data.user_password.length == 0){
			$.alert('请输入密码');
			return false;
		}

		$this.addClass('on');
		$.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: MODULE+'Index/login',
        }).success(function (res) {
            console.log(res);   
            if(res.code == 0){//成功
            	$.alert(res.msg,function(){
                    public.setSession('token',res.data);
            		window.location.replace(MODULE+'PublicJump/media_index');
            	});
            }else{
            	$.alert(res.msg);
            	$this.removeClass('on'); 
            }
        }).fail(function (jqXHR, textStatus, errorThrown) {
            $.alert('登陆失败');
            $this.removeClass('on');            
        });
	});
})